<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1></h1>
    
    <script>
        let h1 = document.querySelector('h1');

        let persons = [
            { "username": "xiaoming1", "password": "1111" },
            { "username": "xiaoming2", "password": "222" },
            { "username": "xiaoming3", "password": "33333" }
        ]

        let user = { username: "admin1", password: "12345" }

        let a = persons.findIndex(function (item) {
            return item.username == user.username && item.password == user.password
        })
        if (a !== -1) {
            h1.innerText = '登录成功'
        } else {
            h1.innerText = '未注册或账号错误'
            persons.push(user)
        }



        // persons.find(function (item) {
        //     class dlzc {
        //         constructor(name, pd) {

        //             if (item.username == name && item.password == pd) {
        //                 return console.log('登陆成功');
        //             } else {
        //                 return console.log('登陆失败');
        //             }
        //         }

        //     }
        //     let p = new dlzc('xiaoming3', 33333);
        // })







    </script>
</body>

</html>